home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / misc / uuclean02.lha / uuclean02.c < prev    next >
C/C++ Source or Header  |  1995-09-12  |  2KB  |  92 lines

  1. /* uuclean.c ... remove extraneous stuff from captured
  2.    uuencoded files 12 Sep 1995 */
  3.  
  4. #include <stdio.h>
  5. #define INCHARS 128
  6. #define MAX 6
  7.  
  8. main(int argc,char *argv[])
  9.  
  10. {
  11.    FILE *infile;
  12.    FILE *outfile;
  13.    char instring[INCHARS];
  14.    char oldstring[INCHARS];
  15.    char teststr[MAX];
  16.    char testend[MAX];
  17.    char oneback[INCHARS];
  18.    char twoback[INCHARS];
  19.    char threeback[INCHARS];
  20.    char current[INCHARS];
  21.    static char beginstr[] =  "begin";
  22.    static char endstr[] = "end";
  23.    static char mstring[] = "M";
  24.    int i;
  25.    int start = 1;
  26.    int end = 1;
  27.    
  28.    if (argc != 3)
  29.    {
  30.       printf ("\n UUCLEAN by rdavis@nyx.cs.du.edu (Robert Davis), version 0.2");
  31.       printf ("\n Usage: %s INPUT OUTPUT \n INPUT and OUTPUT are filenames\n"
  32.       ,argv[0]);
  33.       exit(1);
  34.    }  
  35.  
  36.    if (( infile = fopen(argv[1],"r")) == NULL)
  37.    {
  38.       printf ("\n Cannot open %s\n",argv[1]);
  39.       exit(1);
  40.    }
  41.    
  42.    if (( outfile = fopen(argv[2],"w")) == NULL)
  43.    {
  44.       printf ("\n Unable to open output file %s\n",argv[2]);
  45.       exit(2);
  46.    }
  47.    printf ("\n Working ... \n");
  48.    
  49.    while (fgets (instring,INCHARS,infile) != NULL)
  50.    {   
  51.       strcpy (threeback,twoback);
  52.       strcpy (twoback,oneback);
  53.       strcpy (oneback,current);
  54.       strcpy (current,instring);
  55.    
  56.       /* first, find   begin  */
  57.       for (i=0;i<5;i++)
  58.          teststr[i] = instring[i];
  59.       teststr[i] = 0x00;
  60.       
  61.       for (i=0;i<3;i++)
  62.          testend[i] = instring[i];
  63.       testend[i] = 0x00;
  64.                
  65.       start = (strcmp(beginstr,teststr));
  66.       end = (strcmp(endstr,testend));
  67.            
  68.       if (start == 0)
  69.         fputs (instring,outfile);  /* fputs the first line of the uuencoded file */
  70.         
  71.       if (end == 0)
  72.         { fputs (twoback,outfile); /* this might be a problem with some files */
  73.           fputs (oneback,outfile);
  74.           fputs (instring,outfile);
  75.           break; } /* fputs the last lines of the uuencoded file */
  76.   
  77.       /* compare then copy the new string to the old string */
  78.       
  79.       if ((strcmp (oldstring,instring) != 0) &&
  80.           (strcmp (twoback,instring) != 0) &&
  81.           (strcmp (threeback,instring) != 0))
  82.         {         
  83.          if (*instring == *mstring) /* if first char in line is M */
  84.             { fputs (instring,outfile);
  85.               strcpy (oldstring,instring); }            
  86.         }
  87.    }
  88.    fclose (outfile);
  89.    fclose (infile);
  90.    printf ("\n Done.\n");
  91. }
  92.